Repository navigation
🍽️ feat: Let Schedule Owners Choose Allowed MCP Tools - #18260
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d89e82ec34
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const permittedTools = target.permittedTools | ||
| .map(({ agentId, tools: offeredTools }) => ({ | ||
| agentId, | ||
| tools: offeredTools.filter((tool) => selected.has(tool)), | ||
| })) |
There was a problem hiding this comment.
Make readiness checks respect the owner's tool subset
When an agent selects query and export but the owner allows only query, this now stores a valid partial grant, yet the unchanged preflight in packages/api/src/schedules/mcp.ts:460–483 still authorizes every selected tool. Authorization of export fails with tool_policy_denied, causing the entire preflight to fail before generation. Consequently, partial grants cannot run or pass activation checks; adding an unapproved tool also prevents an otherwise valid grant from running. Resource-bearer connections have the same all-tools assumption in packages/api/src/schedules/bearer.ts:225–228. Update these admission paths to check the granted subset while retaining per-call denial for unapproved tools, and cover a partial grant through the real preflight path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The readiness check now keeps only the servers and tools the grant lists for the agent that selects them (packages/api/src/schedules/mcp.ts). A server with nothing allowed is not connected to, and a grant that covers nothing the agents still select fails with tool_policy_denied. A resource-bearer connection is admitted for the granted selections, not for everything the agents select (grantedSelections in bearer.ts). Per-call denial of an unapproved tool is unchanged.
One step further than the finding: a refused call is recorded against the run, so a model that tried a tool the owner left out would mark the run failed. The run's hook now turns such a call away with a plain message and records nothing (run.ts); the check at the call still refuses and records if the hook is skipped.
Evidence, through the real preflight in runtime.spec.ts: a partial grant is ready and still refuses the left-out tool at the call; a server left out is not connected to; a grant covering nothing selected is not ready. bearer.spec.ts covers the connection, run.spec.ts the hook. Each fails with its fix removed.
| const choice = edited ?? (data ? initialChoice(data) : {}); | ||
| const chosenCount = Object.values(choice).reduce((count, tools) => count + tools.length, 0); | ||
| const setTools = (serverName: string, tools: string[]) => | ||
| setEdited({ ...choice, [serverName]: tools }); |
There was a problem hiding this comment.
Reconcile edited choices when the consent offer changes
If the owner edits selections and an agent subsequently drops a selected server while the dialog remains open, the query's periodic or window-focus refetch removes that server from data.targets, but edited retains its selections indefinitely. Confirm then submits the new offer digest alongside the removed server in allow, which selectAllowed rejects as consent_invalid. Because the removed server no longer has any rendered checkboxes, the owner cannot clear its selections, and retries continue failing until the dialog is closed and reopened. Intersect edited choices with the current offer, or explicitly reset them when the offer changes, rather than submitting hidden stale selections.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 9cbb91a.
The dialog's choice is now derived from the current offer on every render (currentChoice in Consent.tsx): edited selections are kept only for servers and tools still on offer, so a refetch that drops a server or tool also drops its ticks.
Evidence: Consent.spec.tsx ticks tools on two servers, refetches an offer without one server and one tool, and checks the confirm body carries the new digest and only what is still on offer. It fails with the old expression.
| allow: z | ||
| .record(identifier, z.array(identifier).max(256)) |
There was a problem hiding this comment.
Allow the confirmation payload to represent multi-agent tool unions
When reachable agents select more than 256 distinct tools on the same server—for example, two agents selecting 150 disjoint tools each—the offer and stored-grant schemas support that selection because their 256-tool limit applies separately to each agent. However, the new allow payload combines all agents' tools into one server-level array and limits that union to 256. The dialog's server checkbox selects the full union without imposing this limit, so confirming that valid offer receives HTTP 400 from the consent handler. Size the server-level payload bound to accommodate valid multi-agent offers, retaining the existing per-agent limits when constructing the grant.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 9cbb91a.
The per-server allow list is now bounded by what one server can be offered with across its agents (MAX_SCHEDULED_MCP_SERVER_TOOLS, the per-agent tool limit times the per-server agent limit), and the per-agent and per-server-agent limits are named constants the offer schema shares.
Evidence: scheduleConsent.spec.ts accepts 300 tools on one server (two agents with 150 each), accepts the bound and rejects one more.
An enrolled scheduled chat could call an MCP tool only when an operator had listed it in config as read-only, pinned to a hash of its definition. Whether a tool is safe to run with nobody watching is the owner's call, and read-only is a poor proxy for it. The consent offer now lists every MCP tool the agent graph selects on servers whose recipient the operator declared. The owner ticks servers and tools, and the grant stores only those. A tool is allowed at run time when the grant lists it for the calling agent and that agent still selects it; anything else is refused. Selecting another tool later no longer invalidates the grant. The operator `mcpConsent.readOnlyPolicy` list is retired: the loader warns when it is still configured. The stored grant keeps its shape.
The shared Checkbox has no partly-selected appearance, so a server with some tools ticked showed its "allow all" box as checked.
d89e82e to
ccd3aaa
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ccd3aaa542
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!serverTools) { | ||
| selected.delete(server); | ||
| serverAgentIds.delete(server); | ||
| continue; |
There was a problem hiding this comment.
Exclude ungranted servers during runtime catalog loading too
When an agent selects tools from two servers and the owner grants only one, this filtering lets preflight pass, but actual agent initialization still loads both servers. With a cold catalog cache, api/server/services/ToolService.js:1203 calls reinitMCPServer for the excluded server using the scheduled request context. If that server uses resource_bearer, bearer authorization returns consent_missing; api/server/services/Tools/mcp.js records and rethrows that initialization failure, aborting the run before the new tool-denial hook can run. Apply the grant-aware exclusion to runtime catalog loading as well, and cover an omitted resource-bearer server through actual agent initialization rather than only the readiness probe.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 021cb6b.
A run under a grant now asks the tool loader only for what the owner allowed. initializeAgent passes the agent's tool keys through narrowScheduledMCPTools (packages/api/src/schedules/authorization/execution.ts): keys that are not MCP tools are kept, MCP keys are kept only when the grant lists the tool for that agent. A server with nothing allowed is therefore never loaded or connected to during initialization, whatever its credential mode, and a left-out tool is not defined for the model. The change is in the TypeScript initializer; ToolService.js is untouched.
Evidence: initialize.test.ts runs the real initializer with a grant attached to the request, where the agent selects two warehouse tools, one archive tool and web search and the owner allowed one warehouse tool. The loader is asked for that tool and web search, and for nothing on the archive server. execution.spec.ts covers the narrowing per agent, an unauthorized schedule, and that it applies only through the request the grant is attached to. The initializer test fails with the narrowing removed.
Not covered: a resource-bearer server through the CJS loader itself. The loader is a stand-in in that test; what is shown is that it is never asked about the omitted server.
| for (const [serverName, tools] of Object.entries(allow)) { | ||
| const target = offered.find((item) => item.resource.serverName === serverName); | ||
| const selected = new Set(tools); | ||
| if (!target || tools.some((tool) => !allowedTools([target])[serverName].includes(tool))) |
There was a problem hiding this comment.
Compute the offered-tool set once per server
When confirming a multi-agent offer, this predicate calls allowedTools([target]) for every submitted tool, repeatedly flattening, deduplicating, and sorting the entire server's offered tools. Running this exact validation with a schema-valid selection of 20 agents with 256 distinct tools each blocked the Node event loop for approximately 2.2 seconds locally; the schema permits up to 100 agents per server. Because this work is synchronous inside the consent HTTP handler, one confirmation stalls unrelated requests on the same process. Build a set of offered tools once per target and use membership checks for the submitted selections.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 021cb6b.
selectAllowed builds the set of tools on offer once per server and checks membership against it.
Evidence: service.spec.ts confirms 5,120 tools on one server (20 agents with 256 each) and requires it to finish within a second. It took about 1.4 s with the previous check on this machine and fails the test; with the set it takes a few tens of milliseconds. A tool that is not on offer in that selection is still rejected.
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
/quality risk scopes=api |
Quality reportGate: open. The selected checks completed. Scores and risk levels are advisory. Status: completed (success). Actions run, attempt 1.
Change riskTakeaway: 2 changed lines have no test. Highest CRAP among changed functions:
Changed lines with no test
|
| Function | Complexity | Coverage | CRAP | Location |
|---|---|---|---|---|
authorize |
40 | 70% | 83.2 | packages/api/src/schedules/authorization/service.ts:342 |
runPreflight |
45 | 99% | 45.0 | packages/api/src/schedules/mcp.ts:195 |
resolve |
37 | 86% | 41.0 | packages/api/src/schedules/bearer.ts:192 |
loadCustomConfig |
40 | 95% | 40.3 | packages/api/src/app/loader.ts:205 |
(anonymous) |
37 | 90% | 38.3 | packages/api/src/schedules/authorization/enrollment.ts:43 |
authorize |
31 | 87% | 33.0 | packages/api/src/schedules/authorization/execution.ts:194 |
view |
30 | 88% | 31.8 | packages/api/src/schedules/authorization/service.ts:183 |
registerAgent |
20 | 95% | 20.0 | packages/api/src/schedules/authorization/run.ts:106 |
confirm |
13 | 79% | 14.5 | packages/api/src/schedules/authorization/service.ts:269 |
resolve |
12 | 94% | 12.0 | packages/api/src/schedules/authorization/execution.ts:122 |
52 more functions below the threshold (or cut for size) are in report.md.
CRAP = complexity² × (1 − coverage)³ + complexity
Jobs (1)
| Check | Result |
|---|---|
| Change risk (api) | success |
All data (quality-report artifact) · Run page
The gate opens only when the workflow, source selection, tooling verification, and every report job succeed. A report job fails on a failed test in its workspace's own Jest run, a tool error, a job timeout, or an incomplete mutation report, including a mutation shard that reaches its execution budget. A cancelled workflow keeps the gate closed. Scores are advisory. A change-risk file marked incomplete or unavailable, for example by a failed api/ source-alias suite, does not close the gate.
Summary
An enrolled scheduled chat could call an MCP tool only when an operator had listed it in
interface.schedules.mcpConsent.readOnlyPolicyasread_only, pinned to a hash of its definition. That makes the wrong distinction with the wrong person. Many tools both read and write depending on arguments, a read can still leak data, and the person who knows whether a tool should run with nobody watching is the schedule's owner. In practice it also meant an owner could not enroll a schedule at all until an operator had hand-written a hash for every tool.This PR makes the distinction allowed versus not allowed, chosen by the owner. The consent dialog lists every MCP tool the agent graph selects, grouped by server, with a box per tool and one for the whole server. The grant stores only what the owner ticked. At run time a tool is allowed when the grant lists it for the calling agent and that agent still selects it; anything else is refused with
tool_policy_denied. Nothing is allowed by default.A tool the owner left out does not keep the schedule from running, and the run never loads it. The readiness check before activation and before each run looks only at what the grant lists. When the run initializes an agent it asks only for the MCP tools the grant lists for that agent, so a left-out tool is not defined for the model and a server with nothing allowed is not connected to. Should a call to such a tool be made anyway, the run's hook turns it away with a plain message and records nothing; that is the owner's choice, not a failure of the schedule.
Two behaviours change for an existing grant. An agent that later selects another tool no longer invalidates the whole grant; the new tool is simply not allowed until the owner confirms again. And a grant made before this change keeps working, with exactly the tools it listed.
mcpConsent.readOnlyPolicyis retired. The config loader warns when the key is still present, because the schema would otherwise drop it silently.Third step of the unattended-authority work, after #18058 and #18255 (both merged). Related to #13824 and #16157.
How it works
The stored record does not change shape.
permittedToolson a consent used to be the agent's whole selection; it is now the subset the owner allowed, so older and newer replicas read each other's records. An older replica still demands the operator pin and refuses, which fails closed.What was removed: the operator pin check in per-call enforcement, the
checkToolPolicydependency of the consent service, the requirement that the offer's tools appear in the operator list, and the binding of a grant to a digest of the agent's selection. The grant is still bound to the schedule revision, root agent, owner, tenant and the exact resource (URL, configuration revision, credential mode, issuer, audience, scopes).Tool definitions are no longer pinned by this PR. A server that changes what an allowed tool does keeps that tool allowed. Pinning returns in #18273, stacked on this one: a tool is pinned to the definition it first ran with and refused once that changes.
Type of change
Testing
Tested environments/configuration: WSL2, Node.js 24. No external services; the bearer and barrier tests use the real MCP SDK test server.
Automated tests:
packages/api/src/schedules/authorization/service.spec.ts: the grant holds only the chosen tools; a server with nothing chosen is left out and its calls getconsent_missing; a choice that is not on offer, or empty, is rejected without writing; the view staysactivewhen the agent selects another tool and turnschangedwhen it drops an allowed one.packages/api/src/schedules/authorization/execution.spec.ts: a tool the owner did not allow is refused even though the agent selects it; an allowed tool stays authorized after the agent selects another; a dropped tool is refused on approval resume.packages/api/src/schedules/authorization/runtime.spec.ts, through the real readiness check: a grant for some of what the agents select is ready and still refuses the left-out tool at the call; a server left out of the grant is not connected to; a grant that covers nothing the agents still select is not ready.packages/api/src/agents/__tests__/initialize.test.ts, through the real initializer with a grant attached to the request: the tool loader is asked for the allowed MCP tool and the agent's other tools, and for nothing on a server left out; with no grant it is asked for everything.packages/api/src/schedules/authorization/execution.spec.ts: the narrowing keeps what is allowed per agent, leaves a never-authorized schedule alone, and applies only through the request the grant is attached to.packages/api/src/schedules/authorization/service.spec.ts: confirming 5,120 tools on one server (20 agents with 256 each) completes well under a second; the previous check took over two.packages/api/src/schedules/bearer.spec.ts: a resource-bearer connection is admitted for the allowed tools when the agents select more, and refused once they select none of them.packages/api/src/schedules/authorization/run.spec.ts: the hook turns a left-out tool away and records nothing, for an eager agent and one that joins the run later; a tool that is not an MCP tool is still recorded as a refusal; a tool whose key does not name its server is left to the check at the call.packages/api/src/schedules/authorization/enrollment.spec.ts: the offer lists every selected tool with no operator list.packages/api/src/schedules/bearer.spec.ts,barriers.integration.spec.ts,authorization/runtime.spec.ts,receipt.spec.ts,packages/api/src/mcp/__tests__/MCPManager.test.ts: existing coverage moved off the operator pin. The barrier test still proves a per-call denial after an accepted bearer is withheld until durable admission.packages/api/src/app/loader.spec.ts: a config that still carriesreadOnlyPolicyloads and warns.packages/data-provider/src/types/scheduleConsent.spec.ts: the confirm body requires at least one allowed tool, and can name every tool a server can be offered with across its agents (two agents with 150 tools each).client/src/components/SidePanel/Schedules/__tests__/Consent.spec.tsx: tools start unchecked and Confirm is disabled until one is ticked; the server box allows or clears all and is checked only when every tool is; a stored grant pre-ticks what is still on offer; the confirm body carries only ticked tools; with nothing to confirm the allowed tools are listed without boxes; ticks for a server or tool that leaves the offer while the dialog is open are dropped, so the next confirm is not rejected for a choice the owner can no longer see.Each new behaviour was broken in turn and a test confirmed to fail.
npx tsc --noEmitis clean inpackages/api,packages/data-schemas,packages/data-providerandclient.Screenshots / recordings
The real
Consentcomponent under the app's stylesheet in Chromium, fed fixed consent data in place of the API. "Before" is the component and strings fromdev. The Cancel button shows its key because the capture does not initialise the shared package's i18n; the app does.dev)Before, the dialog listed each agent's tools as text and confirmed all of them. After, every tool is a box, nothing is ticked on a first consent, and Confirm stays disabled until one is.
Risk / compatibility
Breaking for operators using
readOnlyPolicy: the list no longer restricts anything. Tools it excluded can now be allowed by an owner. Schedule consent is off by default, so this affects only deployments that enabled it.Definition pinning is gone until #18273. I recommend not enabling
mcpConsenton a deployment that relies on the pin until that PR lands.Existing grants keep the tools they listed. No migration.
Mixed versions: an older replica refuses tools that have no operator pin. Upgrade every replica before owners confirm new grants, as #16681 already requires.